var app = getApp();
// pages/member/shoucang.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    userinfo:{},
    hasmore: true,
    tip: '上拉加载',
    loading: true,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadlist(1)

  },
  


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },
  loadlist: function (page) {
    var that = this;
      this.setData({
        tip: '正在加载',
        loading: true
      });
      app.http.$ajax(
          {
              url: 'v2.favorite/myFavorite',
              data: { p: page },
              loading: false
          },
          {
              success(data) {
                  var data = data.data.data;
                  var hasmore = true;
                  var page = that.data.page;
                  var list = that.data.list;
                  if (data.length < 15) {
                      hasmore = false;
                      that.setData({
                        tip: '暂无数据'
                      })
                  } else {
                    that.setData({
                      tip: '上拉加载'
                    })
                  }
                  
                  list.push(...data);
                  that.setData({ hasmore: hasmore, list: list, page: page,loading: false})
              }
          }
      ) 
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.hasmore) {
      var page = that.data.page;
      page +=1;
      that.loadlist(page);
    } 
  },

})